Imports System.Data
Imports System.Data.SqlClient
Partial Class khachsan
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        If Not Page.IsPostBack Then
            BindGrid()
        End If
    End Sub
    Private Sub BindGrid()

        Dim myConn As New SqlConnection(ConfigurationManager.AppSettings("cons"))

        Dim strWhere As String = " where 1=1"
        If IsNumeric(Request.QueryString("l")) Then
            strWhere += " and idnn=" & Request.QueryString("l")
        End If
        If IsNumeric(Request.QueryString("c")) Then
            strWhere += " and idloaitt=" & Request.QueryString("c")
        End If
        Dim sSql As String = "select idtintuc, tieude,gioithieu,TT,uutien,idnn from tintuc " & strWhere & " order  by idnn, idtintuc desc"
        myConn.Open()
        Dim myAdapter As New SqlDataAdapter(sSql, myConn)
        Dim myDataSet As New DataSet
        myAdapter.Fill(myDataSet, sSql)
        DataGrid1.DataSource = myDataSet
        DataGrid1.DataBind()
        myConn.Close()
    End Sub
    Public Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
        DataGrid1.CurrentPageIndex = e.NewPageIndex
        BindGrid()
    End Sub

End Class

